﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Data.OleDb;

/// <summary>
/// ExcelHelper 的摘要描述
/// </summary>
/// 
namespace com.pro2e.console.generic.util
{
    public class ExcelHelper
    {
        public ExcelHelper()
        {

        }

        /// <summary>
        /// 將EXCEL轉換成DataTable
        /// </summary>
        public static DataTable GetDataTable(string strFilePath, string tableName)
        {
            string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + strFilePath + ";Extended Properties=Excel 8.0;";
            OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM " + tableName , strConn);
            DataSet myDataSet = new DataSet();
            myCommand.Fill(myDataSet, "mytable");

            DataTable dt = myDataSet.Tables["mytable"];

            return dt;
        }

    }
}